package com.asm.rpc.source;



import com.google.gson.*;

import java.lang.reflect.Type;

public class TestGson {
    public static void main(String[] args) {
      /*  Gson gson = new GsonBuilder().registerTypeAdapter(Class.class, new classCodec()).create();
        System.out.println(gson.toJson(String.class));*/
    }
/*
    public static class classCodec implements JsonSerializer<Class<?>>, JsonDeserializer<Class<?>>{

        @Override//反序列化
        public Class<?> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {

            try {
                //拿到类名
                String str = json.getAsString();
                //forName通过类名转成class
                return Class.forName(str);
            } catch (ClassNotFoundException e) {
                throw new JsonParseException(e);
            }
        }

        @Override  //string.class  //序列化
        public JsonElement serialize(Class<?> src, Type type, JsonSerializationContext jsonSerializationContext) {
            //class字节码 -> json

            return new JsonPrimitive(src.getName());
        }
    }*/
}
